package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.Response;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zhaolie
 * @Date 2020/12/16 9:48 下午
 * @Version 1.0
 * @Description
 */

@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Resource
    private EduCourseService courseService;

    @Resource
    private EduTeacherService teacherService;

    // 查询前8条热门课程,前4个名师
    @GetMapping
    private Response index() {
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("view_count");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseQueryWrapper);

        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("sort");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);
        return Response.SUCCESS().data("courseList", courseList).data("teacherList", teacherList);
    }
}
